package com.account.book.controller;

import com.account.book.common.context.UserTokenContextHolder;
import com.account.book.common.response.BaseResult;
import com.account.book.common.response.ResultUtils;
import com.account.book.request.SuggestInfoReqVo;
import com.account.book.response.SuggestInfoResVo;
import com.account.book.service.SuggestInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = {"建议接口"})
@RestController
@RequestMapping("/api/suggestinfo")
public class SuggestInfoController {
    @Autowired
    private SuggestInfoService suggestInfoService;

    /**
     * @param @param suggestInfoReqVo
     * @return @return {@link BaseResult }
     * @author liang-hw
     * @description 新增或者更新建议信息
     * @date 2024/01/15 14:34:37
     */
    @ApiOperation(value = "新增或者更新建议信息", notes = "新增或者更新建议信息")
    @PostMapping("/addAndUpdateSuggestInfo")
    public BaseResult addAndUpdateSuggestInfo(@RequestBody SuggestInfoReqVo suggestInfoReqVo) {
        String userId = UserTokenContextHolder.getUserTokenVOByToken().getUserId();
        suggestInfoService.addAndUpdateSuggestInfo(suggestInfoReqVo, userId);
        return ResultUtils.success();
    }

    /**
     * @param
     * @return @return {@link BaseResult }
     * @author liang-hw
     * @description 查询建议信息
     * @date 2024/01/15 14:42:23
     */
    @ApiOperation(value = "查询建议信息", notes = "查询建议信息")
    @GetMapping("/selectSuggestInfo")
    public BaseResult selectSuggestInfo() {
        String userId = UserTokenContextHolder.getUserTokenVOByToken().getUserId();
        List<SuggestInfoResVo> suggestInfoResVos = suggestInfoService.selectSuggestInfo(userId);
        return ResultUtils.success(suggestInfoResVos);
    }

    /**
     * @param
     * @return @return {@link BaseResult }
     * @author liang-hw
     * @description 删除建议信息
     * @date 2024/01/15 14:42:23
     */
    @ApiOperation(value = "删除建议信息", notes = "删除建议信息")
    @PostMapping("/deleteSuggestInfo")
    public BaseResult deleteSuggestInfo(@RequestBody SuggestInfoReqVo suggestInfoReqVo) {
        suggestInfoService.deleteSuggestInfo(suggestInfoReqVo);
        return ResultUtils.success();
    }
}
